﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DTO;

namespace DAO
{
    public class TacGiaDAO
    {
        public List<TacGiaDTO> LayDanhSachTacGia()
        {
            List<TacGiaDTO> list = new List<TacGiaDTO>();
            try
            {
                QLTVEntities contex = new QLTVEntities();
                var query = from tacgia in contex.TAC_GIAList
                            select tacgia;
                foreach (var tacgiaEF in query)
                {
                    TacGiaDTO tacgiaDTO = new TacGiaDTO();
                    tacgiaDTO.MaTacGia = tacgiaEF.MaTacGia;
                    tacgiaDTO.TenTacGia = tacgiaEF.TenTacGia;
                    list.Add(tacgiaDTO);
                }
            }
            catch (System.Exception)
            {
            }
            return list;
        }

        public void ThemTacGia(TacGiaDTO tacgiaDTO)
        {
            try
            {
                QLTVEntities contex = new QLTVEntities();
                TAC_GIA tacgiaEF = new TAC_GIA();
                tacgiaEF.TenTacGia = tacgiaDTO.TenTacGia;
                contex.AddToTAC_GIAList(tacgiaEF);
                contex.SaveChanges();
            }
            catch (System.Exception)
            {
            }
        }

        public void CapNhatTacGia(TacGiaDTO tacgiaDTO)
        {
            try
            {
                TAC_GIA tacgiaFE = new TAC_GIA();
                tacgiaFE.TenTacGia = tacgiaDTO.TenTacGia;
                QLTVEntities context = new QLTVEntities();
                context.TAC_GIAList.ApplyCurrentValues(tacgiaFE);
                context.SaveChanges();
            }
            catch (System.Exception)
            {
            }
        }
    }
}
